package com.lyf.juc.practice.cas;

import org.junit.Test;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * @author LYF
 * @date 2022/7/11
 */
public class CASTests {

    volatile int i =0;
    int getI(){
        return i;
    }
    synchronized void add() {
        i++;
    }

    final class TestClass{

    }

    @Test
    public void test1(){
        AtomicInteger atomicInteger = new AtomicInteger(5);
        System.out.println(atomicInteger.compareAndSet(5,1)+"::"+atomicInteger.get());
        atomicInteger.getAndIncrement();//自旋
    }
    @Test
    public void test2(){
        AtomicReference<TestClass> atomicReference = new AtomicReference<>();

    }

    //AtomicStampedReference<Integer> atomicStampedReference = new AtomicStampedReference<>(1);

}
